<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ include file="/common/dateUtil.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<head>

 



<script>

//////////////////////////////////////////////////////////////变量
var dap_dis = {};//定义数据处理模块中不连续轨迹操作对象
dap_dis.debug = true;

//////////////////////////////////////////////////////////////初始化控件
//初始化表格
$(function(){
    //初始化表格
    $("#dap_dis_datagrid").datagrid({
        height:"100%",
        toolbar:"#dap_dis_toolbar",//工具条
        pagination:true,//分页工具栏
		pageList:[30,50,100,200],
		pageSize:30,
		singleSelect:true,//单选
		rownumbers:true,//行号
		striped:true,//隔行变色
		fitColumns: false,//填充列
		checkOnSelect: false,//选中则勾选
		selectOnCheck: false,//勾选则选中
    });
});


//接口，初始化相关控件
dap_dis.initDivs = function(){
    this.initDepDiv();
    this.initPaginationDiv();
    this.initDateDiv();
    this.initProcessedDiv();
}

//初始化下拉部门树
dap_dis.initDepDiv = function(){
    //创建下拉部门树
    Utility.createDepTree("dap_dis_depName");
}

//初始化分页控件点击事件
dap_dis.initPaginationDiv = function(){
    let that = this;
    //选择页面事件定义
    $("#dap_dis_datagrid").datagrid("getPager").pagination({
        onSelectPage: function (pageNumber, pageSize) {
            that.queryAllData(pageNumber);
        }
    });
}

dap_dis.initDateDiv = function(){
    let h20 = new Date().getTime() - 1000 * 60 * 60 * 20;
    let h20Str = Utility.dateToString(new Date(h20));
    $("#dap_dis_StartDate").val(h20Str);

    let h12 = new Date().getTime() - 1000 * 60 * 60 * 12;
    let h12Str = Utility.dateToString(new Date(h12));
    $("#dap_dis_EndDate").val(h12Str);
}

//初始化处理结果控件
dap_dis.initProcessedDiv = function(){
    if (!DataUtil.isDefined(parent.userInfo)) {
        if (!DataUtil.isDefined(parent.userInfo.id)) {
            //超级管理员，显示处理结果条件
            if (parent.userInfo.id == 1 ) {
                let obj = document.getElementById('dap_dis_proDiv');
                if(obj != null){
                    obj.style.display = '';
                    let list = [
                        {text:'请选择',value:'-1'},
                        {text:'未处理',value:'unProcessed'},
                        {text:'已处理',value:'processed'},
                    ];
                    $("#dap_dis_processedResult").combobox({
                        textField: "text",
                        valueField: "value",
                        editable: false,
                        data: list,
                    });
                    $("#dap_dis_processedResult").combobox("select",'-1');
                }
            }
        }
    }
}







//////////////////////////////////////////////////////////////加载数据

//查询数据
dap_dis.queryAllData = function(pageNum){
    let that = this;
    let param = this.getQueryParam();
    if(param.parseMsg == ""){
        if(!DataUtil.isDefined(pageNum) &&  pageNum > 0){
            param.pageNumber = pageNum;
            that.outDebug('param : ' , param);
            // let url = globalConfig.webPath + "/basicSlctAction/basicSelectPaginationData.action";   
        }
        let url = globalConfig.webPath + "/dataProcess/getDiscontinuityData.action";

        Utility.getAjaxData(url, JSON.stringify(param), function (data) {
            that.outDebug("接收到不连续轨迹数据：", data);
            if (data.success) {
                $("#dap_dis_datagrid").datagrid("loadData", data.data);
            } else {
                DataUtil.showErrorMsg(data.message);
            }
        });
            // DataUtil.showMsg("开始查询!");
    }else{
        DataUtil.showErrorMsg(param.parseMsg);
    }
}


//获取查询相关参数
dap_dis.getQueryParam = function(){
    let param = {};
    try {
        let formTemp = document.getElementById("dap_dis_slctForm");
        let formData = new FormData(formTemp);
        param = DataUtil.parseFormData2Obj(formData);

        if(!DataUtil.isDefined(param.outList_str)){
            if(param.outList_str != ""){
                let list = param.outList_str.split(",");
                if(list.length > 0){
                    param.outList = list;
                }
            }
        }

        if(!DataUtil.isDefined(param.depId) && param.depId == "0"){
            delete param.depId;
        }

        
        // this.outDebug("18h:" + h18);
        // if(DataUtil.isDefined(param.startDate)){
        //     //如果起始时间为空，则添加为当前时间18小时以前的
        //     param.startDate = h18Str;
        //     $("#dap_dis_StartDate").val(h18Str);
        // }else{
        //     //不为空,则取最近
        //     let startTemp = new Date(param.startDate).getTime();
        //     // this.outDebug("startTimeLong :" + startTemp);
        //     if(startTemp < h18){
        //         param.startDate = h18Str;
        //         $("#dap_dis_StartDate").val(h18Str);
        //     }
        // }

        //查询参数
        if(param.processed == '-1'){
            delete param.processed;
        }

        param.pageNumber = $("#dap_dis_datagrid").datagrid("getPager").data("pagination").options.pageNumber;
	    param.pageSize = $("#dap_dis_datagrid").datagrid("getPager").data("pagination").options.pageSize;
    } catch (error) {
        param.parseMsg += "获取查询参数失败：" + error;
    }
    return param;
}




//////////////////////////////////////////////////////////////datagrid数据格式化






//////////////////////////////////////////////////////////////控件事件

//选择车组
dap_dis.doSelectDep = function(){
	InfoWindow.selectDep();
}

//设置车组信息回调方法，用于查找数组
function onDepSelected(depId,depName){
    dap_dis.outDebug('开始设置车组名称');
	$("#dap_dis_depName").combotree("setValue", depId);
}

//清空时间事件
dap_dis.reset = function(){
    $("#dap_dis_plateNo").val("");
    // $("#dap_dis_depName").val(0);
    $("#dap_dis_depName").combotree('setValue',0);
    $("#dap_dis_StartDate").val("");
    $("#dap_dis_EndDate").val("");
    $("#dap_dis_outList").val("");
}
    

//补数据字段formatter方法
dap_dis.fomatterInsertFlg = function(value,rowData,rowIndex){
    let str = "";
    if(!DataUtil.isDefined(value)){
        //首先设置定位标记
        if(value == "true"){
            str = '无效定位';
            
        }
        let changeFlg = DataUtil.isDefined(rowData.changeFlg) ? "" :rowData.changeFlg;
        if (!DataUtil.isDefined(parent.userInfo)) {
            if (!DataUtil.isDefined(parent.userInfo.id)) {
                //超级管理员，并且changeFlg不为inserted则显示
                if (parent.userInfo.id == 1) {
                    if (changeFlg != 'inserted') {
                        if (rowData.deleted == '0') {
                            if (value == "true") {
                                // DataUtil.outDebug("rowData = " , rowData);
                                str += '&nbsp;&nbsp;&nbsp;&nbsp;<a href=javascript:dap_dis.autoInsertGpsData(' + rowData.Id + ',1);>补数据</a>';
                            } else {
                                str += '&nbsp;&nbsp;&nbsp;&nbsp;<a href=javascript:dap_dis.autoInsertGpsData(' + rowData.Id + ',0);>补数据</a>';
                            }
                        }
                    } else if(changeFlg == 'inserted'){
                        str = '&nbsp;&nbsp;&nbsp;&nbsp;已补';
                    }
                }
            }
        }
    }
    return str;
}

//补数据,type为1，表示自动补数据，为0表示不自动补
dap_dis.autoInsertGpsData = function (id,type) {
    let that = this;
    let str = "是否进行gps数据补轨迹操作？";
    if(type == 1){
        str = "是否自动插入gps轨迹数据并进行809转发？";
    }
    $.messager.confirm('确认', str, function (res) {
        if (res) {
            let disId = DataUtil.isDefined(id) ? 0 : id;
            let disType = DataUtil.isDefined(type) ? 0 :type;
            let url = globalConfig.webPath + "/insertAndTrans/viewInsertGpsDataPage.action?disId=" + id + "&type=" + disType;
            
            let tt  = parent.$('#mainTab');
            let title = "gps历史轨迹补数据"; 
            if(!DataUtil.isDefined(tt)){
                if(tt.tabs('exists', title)){
                    tt.tabs('close',title);
                }
                if(typeof(parent.addTab) == "function"){
                    parent.addTab(title,url);
                    // $(document).oneTime("5s", "dis_refresh_data_850302_1111", function () {
                    //     // DataUtil.outDebug("重新刷新页面：");
                    //     that.queryAllData();
                    // });

                }else{
                    DataUtil.outError("获取父页面方法失败！");
                }
            }

        } 
    });
}


//////////////////////////////////////////////////////////////公共方法

//输出调试信息
dap_dis.outDebug = function(msg,data){
    if(this.debug == true){
        DataUtil.outDebug(msg,data);
    }
}



//////////////////////////////////////////////////////////////加载后执行
$(document).ready(function(){
    dap_dis.outDebug("ready");
    dap_dis.initDivs();//初始化控件
});
</script>

</head>
<body style="min-width:1000px;overflow:auto;">
<div id="dap_dis_toolbar" class="sh_css_basFontSize">
    <form id="dap_dis_slctForm" action="<%=ApplicationPath%>/export.action">
        <input type="hidden" name="queryId" value="dataProcess.selectDiscontinuityData" />
        <input type="hidden" name="changeFlg" value="inserted" />
        <table class="TableBlock" style="width:100%;">
            <tr>
                <td>
                    <div>
                        <span>车牌号码:</span>
                        <input id="dap_dis_plateNo" class="base_inputImpBorder_css" type="text" name="plateNo" style="width:170px;">
                    </div>
                </td>
                <td>
                    <div>
                        <span>车组名称:</span>
                        <select id="dap_dis_depName" name="depId" style="width:170px;"></select>
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                            onclick="dap_dis.doSelectDep();"></a>
                    </div>
    
                </td>
                <td colspan="2">
                    <div>
                        <span>位移起止时间：</span>
                        <input type="text" name="startDate" id="dap_dis_StartDate" class="datetimepicker base_inputImpBorder_css" 
                        style="width:140px;" />
                        <span>  --  </span>
                        <input type="text" name="endDate" id="dap_dis_EndDate" class="datetimepicker base_inputImpBorder_css" 
                        style="width:140px;" />
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="base_hori_flexStartDiv_css">
                        <span>屏蔽车牌号：</span>
                        <input type="text" id="dap_dis_outList" name="outList_str" class="base_inputImpBorder_css" style="width:220px;"/>
                        <span>(备注：多个车牌号用逗号隔开)</span>
                        <div id="dap_dis_proDiv" style="margin-left:15px;display: none;">
                            <span>处理结果：</span>
                            <select id="dap_dis_processedResult" name="processed" style="width:80px;"></select>
                        </div>
                    </div>
                </td>
                <td colspan="2" align="left">
                    <!-- <a id="allAlarmAtnQuery" href="#" class="easyui-linkbutton"
                     data-options="iconCls:'icon-search'" onclick="dap_dis.queryAllData(1);">查询</a> -->
                    <div class="base_hori_flexStartDiv_css">
                        <div id="allAlarmAtnQuery" class="sh_css_btn" onclick="javascript:dap_dis.queryAllData(1);">
                            <div class="ui-icon icon-search" style="width:16px;height:16px;"></div>
                            <span>查询</span>
                        </div>
                        &nbsp;
                        <a id="allAlarmBtnReset" href="#" class="easyui-linkbutton" 
                            data-options="iconCls:'icon-clear'" onclick="dap_dis.reset();">重置</a>&nbsp;
                        <!-- <a id="allAlarmBtnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">导出</a> -->
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
<table id="dap_dis_datagrid" class="easyui-datagrid">
    <thead>
        <tr>
            <th data-options="field:'plateNo'" width="80">车牌号</th>
            <th data-options="field:'termType'" width="80">终端类型</th>
            <th data-options="field:'depName'" width="90">车组</th>

            <th data-options="field:'upSendTime'" width="130">开始时间</th>
            <th data-options="field:'sendTime'" width="130">结束时间</th>

            <th data-options="field:'upLongitude'" width="90">开始经度</th>
            <th data-options="field:'upLatitude'" width="90">开始纬度</th>
            <th data-options="field:'upVelocity'" width="65">开始速度</th>

            
            <th data-options="field:'longitude'" width="90">结束经度</th>
            <th data-options="field:'latitude'" width="90">结束纬度</th>
            <th data-options="field:'velocity'" width="65">结束速度</th>

            <th data-options="field:'mileage'" width="90">起点里程数(Km)</th>
            <th data-options="field:'distance'" width="90">位移距离(Km)</th>
            <th data-options="field:'insertFlg',formatter:dap_dis.fomatterInsertFlg" width="90">是否定位</th>
            <th data-options="field:'createDate'" width="130">检测时间</th>
            <!-- <th data-options="field:'changeFlg'" width="90">标记位</th> -->
        </tr>
    </thead>
</table>
</body>